let json2xml = require('pt-core-common').util.json2xml;
let feedsTemplate = require('./feeds.templates.func');

let feedsInventoryTemplate = {
    messageListTemplate: function(operationType, inventoryList){ // inventoryList = {SKU: xxx, Quantity: 1}
        let messageList = [];
        let index = 0;
        inventoryList.forEach(inventory => {
            index++;
            messageList.push(Object.assign({
                MessageID: index,
                OperationType: operationType
            }, inventory))
        });
        return messageList;
    },
    amazonEnvelopeTemplate2xml: function(sellerId, operationType, inventoryList){
        const messageList = feedsInventoryTemplate.messageListTemplate(operationType, inventoryList);
        return json2xml("AmazonEnvelope", feedsTemplate.amazonEnvelopeTemplate(sellerId, "Inventory", messageList));
    }
};

module.exports = feedsInventoryTemplate;